/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.purchaseView;
/**
 * 说明：
 * 进货管理主窗体
 * @Author：黄盛强
 * @Date：2012-03-20
 */
import java.awt.Graphics;

import javax.swing.ImageIcon;
import javax.swing.JButton;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.factory.ImageFactory;
import com.ruipengkj.view.RPToolBar;
import com.ruipengkj.view.base.BasePanel;

public class PurchaseManagerPanel extends BasePanel{

	private static final long serialVersionUID = 1L;
	private ImageIcon image_bg=ImageFactory.loadImage(ImageFactory.PROCESS_4_BG);
	private ImageIcon image_1=ImageFactory.loadImage(ImageFactory.PROCESS_4_1_BTN);
	private ImageIcon image_2=ImageFactory.loadImage(ImageFactory.PROCESS_4_2_BTN);
	private ImageIcon image_3=ImageFactory.loadImage(ImageFactory.PROCESS_4_3_BTN);
	private ImageIcon image_4=ImageFactory.loadImage(ImageFactory.PROCESS_4_4_BTN);
	private JButton jb1,jb2,jb3,jb4;
	
	public PurchaseManagerPanel(RPToolBar toolBar){
		this.setLayout(null);
		jb1=uiFactory.createRPJButton("库存",image_1,image_1,toolBar.dataCommodityAction);
		jb2=uiFactory.createRPJButton("采购入库",image_2,image_2,toolBar.purchaseEnterAction);
		jb3=uiFactory.createRPJButton("供应商",image_3,image_3,toolBar.dataSupplierAction);
		jb4=uiFactory.createRPJButton("采购退货",image_4,image_4,toolBar.purchaseRetreatAction);
	
		if (!ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL31)) {
			jb1.setEnabled(false);
		}
		if (!ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL41)) {
			jb2.setEnabled(false);
		}
		if (!ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL34)) {
			jb3.setEnabled(false);
		}
		if (!ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL42)) {
			jb4.setEnabled(false);
		}
		
		this.add(jb1);
		this.add(jb2);
		this.add(jb3);
		this.add(jb4);
	}
	
	
	@Override
	public void paintComponent(Graphics g) {
		if(image_bg!=null){
			int pWidth = this.getWidth();
			int pHeight = this.getHeight();
			int mWidth = image_bg.getIconWidth();
			int mHeight = image_bg.getIconHeight();
			int x, y;
			int width, height;
			if ((mWidth <= pWidth) && (mHeight <= pHeight)) {
				x = (pWidth - mWidth) / 2;
				y = (pHeight - mHeight) / 2;
				width = mWidth;
				height = mHeight;
			} else {
				width = pWidth;
				height = pHeight;
				float widthScale = (float) pWidth / (float) mWidth;

				float heightScale = (float) pHeight / (float) mHeight;
				if (widthScale < heightScale)
					height = (int) (mHeight * widthScale);
				else
					width = (int) (mWidth * heightScale);
				x = (pWidth - width) / 2;
				y = (pHeight - height) / 2;
			}
			g.clearRect(0, 0, pWidth, pHeight);
			g.drawImage(image_bg.getImage(), x, y, width, height, this);
			jb1.setBounds(x-90, y+100, 130, 120);
			jb2.setBounds(x+100, y-70, 130, 120);
			jb3.setBounds(x+270, y+100, 130, 120);
			jb4.setBounds(x+100, y+250, 130, 120);
//			g.dispose();
		}
	}

	@Override
	public void clear() {
		// TODO Auto-generated method stub
		
	}
}
